/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ncs.modelo.impl;

import java.util.List;
import ncs.modelo.dao.PerfilDao;
import ncs.modelo.entidades.TPerfil;
import ncs.modelo.util.HibernateUtil;
import org.hibernate.Session;

/**
 *
 * @author rick
 */
public class PerfilDaoImpl implements PerfilDao {

    @Override
    public void actualizar(TPerfil perfil) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            session.beginTransaction();
            session.merge(perfil);
            session.beginTransaction().commit();
        } catch (Exception e) {
            System.out.println("Error en actualizar: " + e.getMessage());
            session.beginTransaction().rollback();
        }
    }

    @Override
    public TPerfil buscarPorId(String id) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        return (TPerfil) session.load(TPerfil.class, id);
    }

    @Override
    public List<TPerfil> buscarTodos() {
        Session session = HibernateUtil.getSessionFactory().openSession();
        return session.createQuery("FROM TPerfil").list();
    }
}
